package com.redwine.app;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.redwine.app.fragments.MyCollectionFragment;
import com.redwine.app.view.PagerSlidingTabStrip;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的收藏页面
 * 作者：gassion on 17/9/5 14:23
 * 最可怕的敌人，就是没有坚强的信念。
 */
public class MyCollectionActivity extends BaseActivity {

    @ViewInject(R.id.viewPager)
    private ViewPager viewPager;
    @ViewInject(R.id.page_tab)
    private PagerSlidingTabStrip pagetTab;
    @ViewInject(R.id.header_title)
    private TextView headerTitle;
    @ViewInject(R.id.layout_back)
    private LinearLayout layoutBack;
    private List<Fragment> fragments;
    private String[] titleList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_collection);
        ViewUtils.inject(this);
        initView();
    }

    private void initView() {
        headerTitle.setText(R.string.my_collection);
        layoutBack.setVisibility(View.VISIBLE);
        titleList = new String[]{getString(R.string.my_collection_supply_of_goods_single),
                getString(R.string.my_collection_purchase_order)};
        if (fragments == null || fragments.isEmpty()) {
            fragments = new ArrayList<>();
            Bundle args = new Bundle();
            MyCollectionFragment findNew = new MyCollectionFragment();
            args.putBoolean(MyCollectionFragment.PARAMS, false);
            findNew.setArguments(args);
            fragments.add(findNew);
            MyCollectionFragment findHot = new MyCollectionFragment();
            args = new Bundle();
            args.putBoolean(MyCollectionFragment.PARAMS, true);
            findHot.setArguments(args);
            fragments.add(findHot);
            viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
                @Override
                public Fragment getItem(int position) {
                    return fragments.get(position);
                }

                @Override
                public CharSequence getPageTitle(int position) {
                    return titleList[position % 3];
                }

                @Override
                public int getCount() {
                    return fragments.size();
                }
            });
            viewPager.setOffscreenPageLimit(2);
            pagetTab.setViewPager(viewPager);
            pagetTab.setIndicatorColorResource(R.color.color_e82565);
            pagetTab.setIndicatorHeight(getResources().getDimensionPixelSize(R.dimen.default_margin_min));
            pagetTab.setUnderlineColorResource(R.color.transparent);
            pagetTab.setTextColor(getResources().getColor(R.color.black));
            pagetTab.setSelectedTextColor(getResources().getColor(R.color.black));
            pagetTab.setTextSize(getResources().getDimensionPixelSize(R.dimen.dp_45));
            pagetTab.setDividerColorResource(R.color.transparent);
            pagetTab.setShouldExpand(true);
        }
    }

    @OnClick({R.id.layout_back})
    public void mClick(View v) {
        switch (v.getId()) {

            case R.id.layout_back:
                finish();
                break;

        }
    }
}
